package com.eqdd.yiqidian.ui.gongneng.renshi.train

import android.annotation.SuppressLint
import android.view.View
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.base.BaseActivity
import com.eqdd.yiqidian.base.Config
import com.eqdd.yiqidian.http.DialogCallBack
import com.eqdd.yiqidian.http.HttpConfig
import com.eqdd.yiqidian.http.HttpResult
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_train_request_detail.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast
import java.util.*

/**
 * Created by jhj on 18-9-11.
 */
class TrainRequestDetailActivity : BaseActivity() {
    override fun initBinding() {
        setContentView(R.layout.activity_train_request_detail)
        initTopTitleBar(View.VISIBLE, "需求详情")
    }

    private var trainBean: TrainRequestDetailActivity.ItemBean? = null

    override fun initData() {
        val id = intent.getIntExtra(Config.ID, -1)
        if (id == -1) {
            toast("获取详情失败")
            finish()
            return
        }
        OkGo.post<HttpResult<ItemBean>>(HttpConfig.BASE_URL + HttpConfig.TRAIN_REQUEST_DETAIL)
                .params("tdid", id)
                .execute(object : DialogCallBack<HttpResult<ItemBean>>(this) {
                    override fun onSuccess(response: Response<HttpResult<ItemBean>>?) {
                        val result = response?.body()
                        if (result?.status == 200) {
                            trainBean = result.items
                            setView()
                        }
                    }
                })


    }

    @SuppressLint("SetTextI18n")
    override fun setView() {
        trainBean?.let {
            tv_title1.text = it.theTheme
            tv_type.text = "培训类别：" + it.theCategory
            tv_budget.text = "培训预算：" + String.format(Locale.CHINA, "%d元", it.budgetedExpense)
            tv_request.text = "其他要求：" + it.otherDemand
            tv_time.text = "计划时间：" + it.thedateStart.substring(0, it.thedateStart.indexOf("T")) + "～" + it.thedateEnd.substring(0, it.thedateEnd.indexOf("T"))
            tv_position.text = "培训地点：" + it.theplace
            tv_company.text = "发布企业：" + it.company
            tv_teacher_industry.text = "行业要求：" + it.lecturerIndustry
            tv_teacher_gender.text = "性别要求：" + if (it.lecturerSex == 0) "不限" else if (it.lecturerSex == 1) "男" else "女"
            tv_teacher_age.text = "年龄要求：" + it.lecturerMinAge.toString() + "～" + it.lecturerMaxAge + "岁"
            tv_teacher_zodiac.text = "属相要求：" + it.lecturerShuXiang
            tv_teacher_taboo.text = "禁忌属相：" + it.lecturerJinJIShuXiang
            tv_teacher_location.text = "常住地址要求：" + it.lecturerAddress
            tv_teacher_education.text = "学历要求：" + it.lecturerEducation
            tv_teacher_job.text = "职称要求：" + it.lecturerZhiCheng
            tv_teacher_language.text = "外语授课要求：" + it.lecturerLanguages
            tv_teacher_work.text = "工作背景要求：" + it.lecturerWorkBackground
            tv_teacher_post.text = "担任职务要求：" + it.lecturerPost

            tv_course.onClick { t ->
                startActivity<TrainCourseActivity>(Config.ID to it.id)
            }
            tv_teacher.onClick { t ->
                startActivity<TrainTeacherActivity>(Config.ID to it.id)
            }
            tv_phone.onClick {

            }

        }

    }


    class ItemBean {
        val id: Int = 0
        val theCategory: String = ""
        val theTheme: String = ""
        val keywords: String = ""
        val thedateStart: String = ""
        val thedateEnd: String = ""
        val theplace: String = ""
        val contacts: String = ""
        val otherDemand: String = ""
        val createTime: String = ""
        val status: Int = 0
        val budgetedExpense: Int = 0
        val demandStatus: Int = 0
        val applyId: Int = 0
        val company: String = ""
        val comid: Int = 0
        val lecturerIndustry: String = ""
        val lecturerSex: Int = 0
        val lecturerMinAge: Int = 0
        val lecturerMaxAge: Int = 0
        val lecturerShuXiang: String = ""
        val lecturerJinJIShuXiang: String = ""
        val lecturerAddress: String = ""
        val lecturerEducation: String = ""
        val lecturerMagor: String = ""
        val lecturerZhiCheng: String = ""
        val lecturerLanguages: String = ""
        val lecturerWorkBackground: String = ""
        val lecturerPost: String = ""
    }
}